Store CargoError inside the ProcessError
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 1 Oct 2016 10:53:42 +0000 (13:53 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 2 Oct 2016 14:28:26 +0000 (17:28 +0300)
src/cargo/util/errors.rs

index 39e22cbe5da45d7357d6fad0500549b916723847..0f1bfe9efb4b356ce134aa93c2a662ec79c258df 100644 (file)
@@ -23,6 +23,7 @@ pub type CargoResult<T> = Result<T, Box<CargoError>>;
 pub trait CargoError: Error + Send + 'static {
     fn is_human(&self) -> bool { false }
     fn cargo_cause(&self) -> Option<&CargoError>{ None }
+    fn as_error(&self) -> &Error where Self: Sized { self as &Error }
 }
 
 impl Error for Box<CargoError> {
@@ -110,13 +111,13 @@ pub struct ProcessError {
     pub desc: String,
     pub exit: Option<ExitStatus>,
     pub output: Option<Output>,
-    cause: Option<Box<Error + Send>>,
+    cause: Option<Box<CargoError>>,
 }
 
 impl Error for ProcessError {
     fn description(&self) -> &str { &self.desc }
     fn cause(&self) -> Option<&Error> {
-        self.cause.as_ref().map(|e| &**e as &Error)
+        self.cause.as_ref().map(|e| e.as_error())
     }
 }
 
@@ -375,7 +376,7 @@ impl CargoError for str::ParseBoolError {}
 // Construction helpers
 
 pub fn process_error(msg: &str,
-                     cause: Option<Box<Error + Send>>,
+                     cause: Option<Box<CargoError>>,
                      status: Option<&ExitStatus>,
                      output: Option<&Output>) -> ProcessError
 {